package blackstar.performance.web.filter;

import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author RayWoo (ayufox@gmail.com)
 *
 */
public class PerformanceFilter implements Filter
{
	private final static Logger LOGGER = Logger.getLogger(PerformanceFilter.class.getSimpleName());

	public void init(FilterConfig config) throws ServletException
	{
		LOGGER.info("init");
	}

	public void destroy()
	{
		LOGGER.info("destroy");
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain filterChain) throws IOException, ServletException
	{
		long start = System.nanoTime();
		try
		{
			filterChain.doFilter(request, response);
		}
		finally
		{
			HttpServletRequest httpRequest = (HttpServletRequest) request;
			HttpServletResponse httpResponse = (HttpServletResponse) response;
			httpRequest.getContentLength();
			long time = (System.nanoTime() - start);
		}
	}
}
